<template>
  <div class="comments-container">
    <header class="comments-header">
      <div class="back-button" @click="goBack">
        <span class="back-arrow">←</span>
      </div>
      <h1>我的评论</h1>
    </header>
    <div class="comments-list">
      <div class="comment-item" v-for="comment in comments" :key="comment.id">
        <div class="comment-details">
          <h2 class="book-title">{{ comment.bookTitle }}</h2>
          <p class="comment-date">{{ comment.date }}</p>
          <div class="comment-content">
            <p>{{ comment.content }}</p>
          </div>
        </div>
      </div>
      <div v-if="comments.length === 0" class="no-comments">
        <p>您还没有任何评论。</p>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      comments: [
        {
          id: 1,
          bookTitle: '书名一',
          date: '2023-10-01',
          content: '这本书非常精彩，故事情节引人入胜，强烈推荐给大家！'
        },
        {
          id: 2,
          bookTitle: '书名二',
          date: '2023-10-05',
          content: '这本书的作者写得很生动，喜欢这种文风。'
        },
        {
          id: 3,
          bookTitle: '书名三',
          date: '2023-10-10',
          content: '内容一般，期待下一本能有所提升。'
        }
      ]
    };
  },
  methods: {
    goBack() {
      console.log("返回按钮被点击"); // 确认按钮被点击
      uni.navigateBack(); // 返回到上一个页面
    }
  }
};
</script>

<style>
.comments-container {
  width: 100%;
  max-width: 375px; /* iPhone 8 width */
  margin: 0 auto;
  padding: 20px;
  background-color: #f7f7f7;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  color: #333;
  font-family: Arial, sans-serif;
  box-sizing: border-box;
}

.comments-header {
  text-align: center;
  margin-bottom: 20px;
  position: relative; /* 以便绝对定位返回按钮 */
}

.back-button {
  position: absolute; /* 绝对定位将返回按钮放置在左上角 */
  left: 10px; /* 向左移动以靠近左上角 */
  top: 10px; /* 向上移动 */
  cursor: pointer; /* 鼠标光标化为指针 */
  font-size: 24px; /* 字体大小可根据需要调整 */
}

.back-arrow {
  color: #333; /* 自定义箭头颜色 */
}

.comments-list {
  background-color: #ffffff;
  border-radius: 4px;
  padding: 15px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.comment-item {
  margin-bottom: 15px;
  padding: 10px;
  border-bottom: 1px solid #eee;
}

.comment-item:last-child {
  border-bottom: none;
}

.comment-details {
  margin-bottom: 10px;
}

.book-title {
  font-weight: bold;
  font-size: 16px;
  margin: 0;
}

.comment-date {
  font-size: 12px;
  color: #888;
  margin: 5px 0;
}

.comment-content {
  font-size: 14px;
  color: #555555;
}

.no-comments {
  text-align: center;
  color: #777;
  padding: 20px;
}
</style>